import 'package:fate_blind_box/routes/page_route_names.dart';
import 'package:fate_blind_box/utils/loading.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class PayCodeViewModel with ChangeNotifier {
  /// 验证码是否输入错误
  var isCodeError = false;

  /// 支付密码控制器
  TextEditingController payCodeController = TextEditingController();

  PayCodeViewModel._() {
    payCodeController.addListener(() {
      isCodeError = false;
      notifyListeners();
    });
  }

  factory PayCodeViewModel() => PayCodeViewModel._();

  /// 验证码输入框内容
  verifyPayCode(BuildContext context, String passWord) {
    verifyPayRequest(passWord).then((value) {
      if (!value) {
        Navigator.pop(context, true);
      }
    });
  }

  ///  校验支付密码
  Future<bool> verifyPayRequest(String passWord) async {
    payCodeController.clear();
    toast("支付密码错误请重新支付");
    // TODO: 调用接口验证支付密码
    // var result = await PayPasswordServer.verifyPayPassword(passWord);
    // if (result) {
    //   isCodeError = false;
    //   return false;
    // } else {
    //   isCodeError = true;
    // }
    // notifyListeners();
    return true;
  }

  /// 忘记密码,重新设置支付密码
  void faceVerification() async {
    Get.toNamed(PageRouteNames.phoneVerification);
    // var manager = FaceVerifyManager();
    //
    // Map<String, dynamic> verificationResult =
    //     await manager.performFaceVerification();
    // if (verificationResult['success']) {
    //   debugPrint("验证成功");
    //   HzNavigator.push(SettingRouter.setPayPasswordPage, arguments: {
    //     "status": PasswordStatus.forgot,
    //     'signature': verificationResult['signature'],
    //   });
    // }
  }
}
